#include "mapIcons.h"

//icon+++++++++++++++++++++++++++++++++++++++++++
void icon::setImage(string str){
    image = image->create_from_png(str.append("_icon.png"));
    infoImage = infoImage->create_from_png(str.append("_info.png"));
}
void icon::draw(Cairo::RefPtr<Cairo::Context> cr, int center[2], double color[3]){
    cr->save();
    cr->set_source_rgb(color[0], color[1], color[2]);
    draw(cr, center);
    cr->restore();
}
void icon::draw(Cairo::RefPtr<Cairo::Context> cr, int center[2]){
    cr->save();

    //draw an image, if its tehre
    if(image != NULL){
        cr->set_source(image, center[0] - image->get_width(), center[1] - image->get_height());
        cr->paint();
        cr->restore();
        return;
    }

    //draw from vectors
    cr->move_to((center[0] - tileWidth / 2 - 5), (center[1] - tileHeight / 2 - 5));
    cr->line_to((center[0] + tileWidth / 2 - 5), (center[1] + tileHeight / 2 - 5));
    cr->move_to((center[0] + tileWidth / 2 - 5), (center[1] - tileHeight / 2 - 5));
    cr->line_to((center[0] - tileWidth / 2 - 5), (center[1] + tileHeight / 2 - 5));
    cr->stroke();

    cr->restore();
}
void icon::infodraw(Cairo::RefPtr<Cairo::Context> cr, int size[2]){
    cr->save();
    cr->set_source_rgb(0,0,0);
    cr->fill();
    cr->set_source_rgb(1,1,1);
    cr->move_to(2, 2);
    cr->line_to(size[0] - 2, size[1] - 2);
    cr->move_to(size[0] - 2, 2);
    cr->line_to(2, size[1] - 2);
    cr->stroke();
    cr->restore();
}
//===============================================
//icon table+++++++++++++++++++++++++++++++++++++
vector<icon*> iconTable::iconList;

void iconTable::intitalize(){
    iconList.push_back(new icon());
}
void iconTable::draw(int iconId, Cairo::RefPtr<Cairo::Context> cr, int center[2]){
    if(iconId < iconList.size()){
        iconList[iconId]->draw(cr, center);
        return;
    }
    iconList[0]->draw(cr, center);
}
void iconTable::draw(int iconId, Cairo::RefPtr<Cairo::Context> cr, int center[2], double color[3]){
    if(iconId < iconList.size()){
        iconList[iconId]->draw(cr, center, color);
        return;
    }
    iconList[0]->draw(cr, center, color);
}
int iconTable::addIcon(icon* icn){
    iconList.push_back(icn);
    return iconList.size() - 1;
}
//===============================================

